package com.surfacing.rcp.client.view;


import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.part.ViewPart;

import com.surfacing.rcp.client.controller.NewJournalAction;
import com.surfacing.rcp.client.modelManager.MyToolbarManager;
import com.surfacing.rcp.client.perspectives.SwitchToAdminPerspective;
import com.surfacing.rcp.client.perspectives.SwitchToJournalPerspective;
import com.surfacing.rcp.client.util.CustomColors;
import com.surfacing.rcp.model.factory.ImageFactory;

/**
 * The navigation on the top including the toolbar.
 * 
 * @author Michael
 */
public class NavigationView extends ViewPart {
	private static final Logger log = Logger.getLogger(NavigationView.class);
	public static final String ID = "com.surfacing.rcp.client.view.navigation";

	// properties
	// private static Image imageLogo = ImageFactory.getInstance()
	// .getRegisteredImage("toolbar.logo");
	private static Image imageLogo = ImageFactory.getInstance()
			.getRegisteredImage("toolbar.logo");

	@Override
	public void createPartControl(Composite parent) {
		GridLayout layout = new GridLayout(5, false);
		parent.setLayout(layout);
		parent.setBackground(CustomColors.SECTION_BACKGROUND);

		// create a group for the perspective switch
		final Group perspectiveGroup = new Group(parent, SWT.NONE);
		perspectiveGroup.setLayout(new GridLayout());
		perspectiveGroup.setLayoutData(new GridData());
		perspectiveGroup.setBackground(CustomColors.SECTION_BACKGROUND);
		perspectiveGroup.setText("Ansichten");

		// the toolbar to switch the views
		final MyToolbarManager tbmView = new MyToolbarManager(new ToolBar(
				perspectiveGroup, SWT.FLAT));
		tbmView.getControl().setBackground(CustomColors.SECTION_BACKGROUND);
		tbmView.getControl().setLayoutData(
				new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
		tbmView.add(new SwitchToJournalPerspective());
		tbmView.add(new SwitchToAdminPerspective());
		tbmView.update(true);

		// create a group for the perspective switch
		final Group createGroup = new Group(parent, SWT.NONE);
		createGroup.setLayout(new GridLayout());
		createGroup.setLayoutData(new GridData());
		createGroup.setBackground(CustomColors.SECTION_BACKGROUND);
		createGroup.setText("Journal");

		// Create the toolbar
		final MyToolbarManager tbmCreate = new MyToolbarManager(new ToolBar(
				createGroup, SWT.FLAT));
		tbmCreate.getControl().setBackground(CustomColors.SECTION_BACKGROUND);
		tbmCreate.getControl().setLayout(new GridLayout());
		tbmCreate.getControl().setLayoutData(new GridData());
		tbmCreate.add(new NewJournalAction());
		tbmCreate.update(true);

		// final Group adminGroup = new Group(parent, SWT.NONE);
		// adminGroup.setLayout(new GridLayout());
		// adminGroup.setLayoutData(new GridData());
		// adminGroup.setBackground(CustomColors.SECTION_BACKGROUND);
		// adminGroup.setText("Admin");

		// Create the toolbar
		// final MyToolbarManager adminCreate = new MyToolbarManager(new
		// ToolBar(
		// adminGroup, SWT.FLAT));
		// adminCreate.getControl().setBackground(CustomColors.SECTION_BACKGROUND);
		// adminCreate.getControl().setLayout(new GridLayout());
		// adminCreate.getControl().setLayoutData(new GridData());
		// // tbmCreate.add(new EditorNewJournalAction(PlatformUI.getWorkbench()
		// // .getActiveWorkbenchWindow()));
		//
		// adminCreate.add(new EditorNewNfsAction(PlatformUI.getWorkbench()
		// .getActiveWorkbenchWindow()));
		// adminCreate.add(new EditorNewDoctorAction(PlatformUI.getWorkbench()
		// .getActiveWorkbenchWindow()));
		// adminCreate.add(new EditorNewDienststelleAction(PlatformUI
		// .getWorkbench().getActiveWorkbenchWindow()));
		// adminCreate.add(new EditorNewTransportzielAction(PlatformUI
		// .getWorkbench().getActiveWorkbenchWindow()));
		// adminCreate.add(new
		// EditorNewEinsatzartAction(PlatformUI.getWorkbench()
		// .getActiveWorkbenchWindow()));
		// adminCreate.add(new EditorNewAnforderungAction(PlatformUI
		// .getWorkbench().getActiveWorkbenchWindow()));

		// adminCreate.update(true);

		Composite comp1 = new Composite(parent, SWT.NONE);
		comp1.setBackground(CustomColors.SECTION_BACKGROUND);
		GridData gd = new GridData(SWT.END, SWT.CENTER, false, false);
		// gd.widthHint = 490;
		gd.widthHint = SWT.MAX - 60;
		comp1.setLayoutData(gd);

		GridData gd2 = new GridData(SWT.END, SWT.CENTER, false, false);
		Label headerImageLabel = new Label(parent, SWT.NONE);
		headerImageLabel.setImage(imageLogo);
		headerImageLabel.setLayoutData(gd2);
	}

	@Override
	public void setFocus() {
	}
}
